package jp.sourceforge.akjrcp.util;

import java.io.File;

import jp.sourceforge.akjrcp.akj_betas.Akj_betasPlugin;
import jp.sourceforge.akjrcp.flvtools.basic.FFMpegPage;

public class FileNameUtils {


	public static String getChangedExtensionName(File file,String extension){
		File newFile=null;
		String baseName=null;
		if(file.getName().lastIndexOf(".")==-1){
			baseName=file.getName();
		
		}else{
			int index=file.getName().lastIndexOf(".");
			baseName=file.getName().substring(0,index);
		}
		newFile=new File(file.getParent(),baseName+"."+extension);
		int index=1;
		
		
		
		
		while(newFile.exists()){
			String specific="("+index+")";
			
			newFile=new File(file.getParent(),baseName+specific+"."+extension);
			index++;
		}
		
		return newFile.getAbsolutePath();
	}
	
	public static boolean changeExtension(File file,String extension){
		
		return file.renameTo(new File(getChangedExtensionName(file,extension)));
	}

}
